package com.ctshk.rpc.bus.mapper;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.ctshk.common.service.mapper.CtsBaseMapper;
import com.ctshk.common.utils.Assist;
import com.ctshk.rpc.bus.dto.BusProductCostDTO;
import com.ctshk.rpc.bus.dto.BusProductCostPriceDTO;
import com.ctshk.rpc.bus.entity.BusProductCost;

/**
 * <p>
 * 巴士产品成本表 Mapper 接口
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-19
 */
public interface BusProductCostMapper extends CtsBaseMapper<BusProductCost> {

    /**
     * 根据产品id查询产品成本集合
     * @param busProductId
     * @return
     */
    @Select("<script>"+"select id,bus_product_id,cost_name,currency_id,currency_name from t_bus_product_cost \n" +
            "where bus_product_id = #{busProductId} \n" +
           "</script>")
    List<BusProductCostDTO> queryList(@Param("busProductId") Long busProductId);




    /**
     * 查询产品成本价格
     */
    @Select("<script>"+"select e.passenger_id,e.price from t_bus_product_cost a " +
            "left join t_bus_product b on a.bus_product_id  = b.id \n" +
            "left join t_bus_product_cost_date c on a.id = c.cost_id \n" +
            "left join t_bus_product_cost_price e on a.id = e.cost_id \n" +
            "WHERE b.is_deleted = 0 \n" +
            "AND c.date_begin &lt;=#{queryDate} and c.date_end &gt;=#{queryDate}\n" +
            "AND b.id =#{productId}\n" +
            "</script>")
    List<BusProductCostPriceDTO> queryPrice(@Param("productId") Long productId, @Param("queryDate") LocalDate queryDate);
    
    /**
     * 查询产品成本价格列表
     * @param productId
     * @param queryDate
     * @return key：旅客类型；value：价格
     */
    default Map<Long, BigDecimal> queryPriceMap(Long productId, LocalDate queryDate) {
    	List<BusProductCostPriceDTO> list = queryPrice(productId, queryDate);
    	return Assist.forEachToMap(list, BusProductCostPriceDTO::getPassengerId, BusProductCostPriceDTO::getPrice);
    }
}
